package com.ac.core.taglib;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.springframework.jdbc.core.JdbcTemplate;

import com.caac.core.config.Config;
/**
 * 
 * @author Administrator
 *
 */
public class DataTag extends BodyTagSupport {
    private static final long serialVersionUID = 1L;
    private String query;
    private String param;
    private String tmpId;
    private String id;

    public DataTag() {
        super();
    }

    public void release() {
        super.release();
        query = null;
        param = null;
        tmpId = null;
        id = null;
    }

    public int doStartTag() throws JspException {
        return EVAL_BODY_INCLUDE;
    }

    public int doEndTag() throws JspException {
    	HttpServletRequest req = (HttpServletRequest)pageContext.getRequest();
        JdbcTemplate jt = (JdbcTemplate)Config.getInstance().getBean("jdbcTemplate");
        if(tmpId!=null){
    		String sql = "SELECT WR_CONT FROM HND_TMP_WHERE WHERE ID='"+ tmpId + "'";
    		query = (String) jt.queryForObject(sql, String.class);       	
        }
        List fList = null;
        if(param==null){
        	fList = jt.queryForList(query);
        }else{
            String[] params = param.split(",");
    		fList = jt.queryForList(query,params);
        }
		req.setAttribute(id, fList);      	
        return EVAL_PAGE;
    }
   
 	public String getQuery() {
		return query;
	}

	public void setQuery(String query) {
		this.query = query;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setParam(String param) {
		this.param = param;
	}

	public String getParam() {
		return param;
	}

	public void setTmpId(String tmpId) {
		this.tmpId = tmpId;
	}

	public String getTmpId() {
		return tmpId;
	}
}
